$.getJSON("http://192.168.20.41/daojucheng-juchengpin/project/php/sever.php?key=?","hide=limitTime",data =>{
    let count = 0,num = 0;
    let box = $(".page");
    for(let i = 0 ;i < 12 ; i++ ){
        count++;
        let li = $(`<li onclick='detail(this,${i})'><a href='javascript:void(0);'></a></li>`);
        if(data[i].status == 0){
            let div0 = $(`<div class='i-comm i-out'><span class='mark-txt'>缺货</span></div>`);
            let model = $(`<div class="out-zzc"></div>`);
            li.append(div0);
            li.append(model);
        }else if(data[i].status == 1){
            
        }else if(data[i].status == 2){
            let div2 = $(`<div class='i-comm i-mark'><span class='mark-txt'>新品</span></div>`);
            li.append(div2);
        }else if(data[i].status == 3){
            let div3 = $(`<div class='i-comm i-mark'><span class='mark-txt'>限定新品</span></div>`);
            li.append(div3);
        }
        let img = $(`<img src='../img/${data[i].link}' width='280' height='268'>`);
        let div = $(`<div class='good-info'><p class='good-name'>${data[i].name}</p><div class='good-pri'><span class='new-pri'>￥${data[i].newprice}</span><span class='old-pri'>￥${data[i].oldprice}</span></div></div>`);
        li.append(img);
        li.append(div);
        $(".good-list>ul").append(li);
        if((count - 1) % 3  == 0){
            num++;
            if(num == 1){
                let btn = $(`<span onclick='btn(this,${num})' class='page_btn active'><a href='javascript:void(0);'>${num}</a></span>`);
                box.append(btn);
            }else{
                let btn = $(`<span onclick='btn(this,${num})' class='page_btn'><a href='javascript:void(0);'>${num}</a></span>`);
                box.append(btn);
            }
        }
    }
    let btnl = $(`<span onclick='left(this)' i=1 class='p_prev'><a href='javascript:void(0);'><i class='ico-center ico-arrleft'></i></a></span>`);
    let btnr = $(`<span onclick='right(this)' i=1 class='p_next'><a href='javascript:void(0);'><i class='ico-center ico-arrright'></i></a></span>`);
    box.append(btnr);
    box.append(btnl);
},"JSON")

function btn(e,n){
    $(".page_btn").removeClass("active");
    e = window.event;
    target = e.srcElement;
    if(target.children.length == 0){
        target.parentNode.className = "page_btn active";
    }else{
        target.className = "page_btn active";
    }
    let m =target.innerHTML;
    $(".p_next").attr("i",n);
    $(".p_prev").attr("i",n);
    render(n);
}
function render(m){
    $.getJSON("http://192.168.20.41/daojucheng-juchengpin/project/php/sever.php?key=?","hide=limitTime",data =>{
        let count = m * 8,num = m * 8;
        let j = m-1;
        let box = $(".page");
        $(".good-list>ul").html("");
        for(let i = j * 12 ;i < j * 12 + 12; i++){
            count++;
            let li = $(`<li onclick='detail(this,${i})'><a href='javascript:void(0);'></a></li>`);
            if(i < data.length){
                if(data[i].status == 0){
                    let div0 = $(`<div class='i-comm i-out'><span class='mark-txt'>缺货</span></div>`);
                    let model = $(`<div class="out-zzc"></div>`);
                    li.append(div0);
                    li.append(model);
                }else if(data[i].status == 1){
                    
                }else if(data[i].status == 2){
                    let div2 = $(`<div class='i-comm i-mark'><span class='mark-txt'>新品</span></div>`);
                    li.append(div2);
                }else if(data[i].status == 3){
                    let div3 = $(`<div class='i-comm i-mark'><span class='mark-txt'>限定新品</span></div>`);
                    li.append(div3);
                }
                let img = $(`<img src='../img/${data[i].link}' width='280' height='268'>`);
                let div = $(`<div class='good-info'><p class='good-name'>${data[i].name}</p><div class='good-pri'><span class='new-pri'>￥${data[i].newprice}</span><span class='old-pri'>￥${data[i].oldprice}</span></div></div>`);
                li.append(img);
                li.append(div);
                $(".good-list>ul").append(li);
            }
        }
    },"JSON")
}
//左箭头
function left(e){
    e = window.event;
    target = e.srcElement;
    if($(".active").text() > 1){
        $(".active").removeClass("active").prev().addClass("active");
        let m = $(".active").text();
        $(".p_next").attr("i",m);
        $(".p_prev").attr("i",m);
        render(m);
    }
}
//右箭头
function right(e){
    e = window.event;
    target = e.srcElement;
    if($(".active").text() < 4){
        $(".active").removeClass("active").next().addClass("active");
        let m = $(".active").text();
        $(".p_next").attr("i",m);
        $(".p_prev").attr("i",m);
        render(m);
    }
}
//排序五个
function sort(){
    $(".flt-arrow").click(e =>{
        e = window.event;
        target = e.srcElement;
        if(target.children.length == 0){
            $(".flt-arrow").removeClass("cur");
            if(target.innerHTML == "默认"){
                target.className = "flt-arrow cur";
            }else{
                $(".i-arrgray").removeClass("i-arrbbot");
                target.parentNode.className = "flt-arrow cur";
                target.nextElementSibling.className = "i-comm i-arrgray i-arrbbot";
            }
        }
    });
}
sort();
//跳转详情页
function detail(e,id){
    $.getJSON("http://192.168.20.41/daojucheng-juchengpin/project/php/sever.php?key=?","hide=limitTime",data =>{
        sessionStorage.id = id+1;
        location = "../html/jc_details.html";
    })
}


